Skip to content

Enhances Prism.Maui navigation test coverage#3397

Merged
dansiegel merged 11 commits into
masterfrom
dev/ds/maui-tests
May 14, 2026
Merged

Enhances Prism.Maui navigation test coverage#3397
dansiegel merged 11 commits into
masterfrom
dev/ds/maui-tests

Conversation

@dansiegel

@dansiegel dansiegel commented May 8, 2026

Copy link
Copy Markdown
Member

Description of Change

This pull request significantly enhances the test coverage for Prism.Maui's navigation system, focusing on both the PageNavigationService and INavigationBuilder extensions. It introduces new test fixtures to cover various success and failure paths, edge cases, and validation logic, ensuring robustness across different navigation scenarios.

To facilitate these comprehensive tests, several mocking classes and test infrastructure components have been refactored or added. Additionally, async void navigation methods within NavigationBuilderExtensions are now explicitly excluded from code coverage, acknowledging their role as fire-and-forget UI entry points, with testable NavigateAsync counterparts already covered.

Bugs Fixed

API Changes

Added:

  • System.Diagnostics.CodeAnalysis namespace usage
  • [ExcludeFromCodeCoverage] attribute to INavigationBuilder.Navigate extension methods

Changed:

  • NavigationPop record's Page property type to nullable Page?

Behavioral Changes

  • async void Navigate extension methods are now marked for exclusion from code coverage, improving internal code quality metrics. This does not alter the functional behavior for consumers of the library.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be532fd391

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/Maui/Prism.Maui.Tests/Mocks/PageNavigationServiceMock.cs Outdated
@dansiegel dansiegel force-pushed the dev/ds/maui-tests branch from e202fa8 to 9e23a83 Compare May 12, 2026 13:43
dansiegel added 9 commits May 13, 2026 07:22
Adds extensive unit tests for `PageNavigationService` and `INavigationBuilder` extensions,
covering various failure paths and edge cases to improve robustness.

Refactors core navigation test infrastructure, including container, application,
window manager, and page accessor mocks, to enable more comprehensive and accurate testing.

Excludes `async void Navigate` extension methods from code coverage, clarifying
their role as UI entry points not intended for direct unit testing.
Improves `TabbedPage` selected tab resolution by matching registered view names alongside CLR type names, addressing scenarios where they diverge.

Refactors `PageNavigationService` unit tests for increased reliability:
- Converts `async void` tests to `async Task`.
- Explicitly asserts `INavigationResult` for navigation outcomes.
- Introduces a shared `PageNavigationEventRecorder` for consistent tracking of page lifecycle events across DI-resolved instances.
- Adds helper methods for navigating complex visual trees (e.g., finding tabbed or flyout pages).

Updates `EventToCommandBehavior` tests to use `CollectionView` and a more flexible mock for event raising, ensuring accurate behavior simulation.
Assign PageNavigationContainerMock.SharedNavigationRecorder from
PageNavigationServiceMock so DI-resolved pages record lifecycle events.

Update NavigateAsync_From_NavigationPage_When_NotClearNavigationStack_And_SamePage
to assert the Prism re-navigation sequence on the existing top page; the prior
recorder.IsEmpty check passed only because resolved pages had no recorder.
Ensure region hosts inside region guests receive Parent so nested regions
register correctly after layout (GitHub #3332).

Add DryIoc region fixture test with explicit measure/arrange for nested
ContentView regions.
Remove the dialog from IDialogContainer.DialogStack before invoking the
completion callback so callers can navigate immediately after the dialog
closes (GitHub #3395).

Add DryIoc regression test covering GoBackAsync after ShowDialogAsync.
Add NestedRegionPage with RequestNavigate into OuterRegion; outer guest navigates InnerRegion on IRegionAware.OnNavigatedTo (GitHub #3332), mirroring community nested-region samples.

Add ViewD command to await ShowDialogAsync then GoBackAsync for GitHub #3395.
Issue3332_NestedContentRegion_InnerRegionReceivesGuest_AfterLayout now uses RequestNavigate for the outer region and relies on MockOuterGuestViewModel.OnNavigatedTo to navigate the inner region, matching the e2e sample. Mock inner VM implements IRegionAware for navigation target resolution.
DialogContainerPage runs PushModalAsync/PopModalAsync and DialogStack updates via IDispatcher.DispatchAsync when dispatch is required; run inline when already on the UI thread or when no dispatcher (avoids nested DispatchAsync deadlock during re-entrant close). Consolidated null/IsDispatchRequired guard per review.
Changes `GlobalPackageReference` to `PackageReference` in `Directory.Build.props` for several packages. This ensures consistent package referencing when Central Package Management (CPM) is enabled, as `GlobalPackageReference` is primarily used for version definitions within `Directory.Packages.props`.
@dansiegel dansiegel force-pushed the dev/ds/maui-tests branch from 9e23a83 to 0abb611 Compare May 13, 2026 15:14
dansiegel added 2 commits May 14, 2026 06:37
Replaces traditional .sln files with .slnx solution filter files for all
e2e samples and the main library. This enables more flexible solution
management, allowing developers to load specific subsets of projects to
improve IDE performance and reduce clutter.
@dansiegel dansiegel requested a review from brianlagunas as a code owner May 14, 2026 12:54
@dansiegel dansiegel added this to the 9.1 milestone May 14, 2026
@dansiegel dansiegel merged commit 6ed21e2 into master May 14, 2026
10 checks passed
@dansiegel dansiegel deleted the dev/ds/maui-tests branch May 14, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant